/**
*	@file AST.h
*
*	@brief this header file is defining the AST structure
*
*	@author li yuchen
*
*	@date 1/28/2011
*/
#ifndef AST_H
#define AST_H

#include "TNode.h"
#include "VarTable.h"
#include <string>
using namespace std;


class AST{
public:

	/** @brief return the root of AST */
	inline static TNode* get_p_tnode_AST_root(){return p_tnode_AST_root_;};

	/**
	*	@brief create a TNode with the required type
	*		pos-condition: return the reference to the TNode created.
	*	@param type always required
	*	@param value fill in NOT_APPLICABLE if not needed
	*	@param stmt_num fill in NOT_APPLICABLE if not needed
	*/
	static TNode* CreateTNode(TNodeType type, TNodeValue value, StmtNum stmt_num);

	/** 
	*	@brief set a parent child relationship between the two TNode
	*		both nodes could not be NULL, parent should not have child
	*		child should not have any siblings
	*/
	static void SetParent(TNode* parent, TNode* child);

	/**
	*	@brief set a sibling relationship between the two TNode
	*		pre-condition: 
	*		both nodes could not be NULL, the parent of left sibling has already been set
	*		pos-condition: 
	*		besides the sibling relation has been set, the right sibling will share the parent with left
    *		but the parent of them will still has the child as left
	*/
	static void SetSibling(TNode* left, TNode* right);

	/** 
	*	@brief check whether if assign tnode has modified the variable: modifies_var, and right pattern is matched
	*		if modifies_var is 0 and right is NULL return true
	*		if modifies_var is 0, ignore and check right_pattern
	*		if right_pattern is NULL, ignore and check var
	*	@param is_relaxed represent if the query is a relaxed pattern or strict pattern
	*/
	static bool IsPatternMatch(TNode* assign_tnode,VarIdx modifies_var_idx,TNode* right_pattern,bool is_relaxed);

private:
	static TNode* p_tnode_AST_root_ ;
	static bool StrictPatternMatch(TNode* expr_root,TNode* pattern_root);
	static bool RelaxedPatternMatch(TNode* expr_root,TNode* pattern_root);
};
/*! \class AST AST.h "AST.h"
*   \brief capture the whole structure of SIMPLE program
*/
#endif